package com.tongyi.lizhishop.common;

import android.os.Bundle;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;

import com.zhy.adapter.recyclerview.MultiItemTypeAdapter;
import com.zhy.adapter.recyclerview.base.ItemViewDelegate;
import com.zhy.adapter.recyclerview.base.ViewHolder;

import java.util.List;

/**
 * Created by meijun on 17-12-11.
 */

public abstract class AbstractBaseLayoutActivity extends RecycleViewActivity {

    protected MultiItemTypeAdapter multiItemTypeAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initView();
    }

    private void initView() {
        recyclerview.setLayoutManager(new LinearLayoutManager(this));
        recyclerview.setItemAnimator(new DefaultItemAnimator());
        recyclerview.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL));
        multiItemTypeAdapter = new MultiItemTypeAdapter(this, getList());
        multiItemTypeAdapter.addItemViewDelegate(new ItemViewDelegate() {
            @Override
            public int getItemViewLayoutId() {
                return getTopItemView();
            }

            @Override
            public boolean isForViewType(Object item, int position) {
                return position == 0;
            }

            @Override
            public void convert(ViewHolder holder, Object o, int position) {

            }
        });
        multiItemTypeAdapter.addItemViewDelegate(new ItemViewDelegate() {
            @Override
            public int getItemViewLayoutId() {
                return getBottomItemView();
            }

            @Override
            public boolean isForViewType(Object item, int position) {
                return position != 0;
            }

            @Override
            public void convert(ViewHolder holder, Object o, int position) {

            }
        });
        recyclerview.setAdapter(multiItemTypeAdapter);

    }

    /**
     * 复写此方法返回数据集合
     * @return
     */
    protected abstract List getList();

    /**
     * 复写此方法返回第二个itemlayout
     * @return
     */
    protected abstract int getBottomItemView();

    /**
     * 获取取上一部分的视图
     * @return
     */
    protected abstract int getTopItemView();

}

